<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>while实现1到100相加求和</title>
    <script>
    function sumNumbers() {
        var sum = 0;
        var a = 1;
    
        while (a <= 100) {
            sum += a;
            a++;
        }
    
        alert("1到100的和为：" + sum);
    }
    </script>
    </head>
    <body>
    <button onclick="sumNumbers()">计算1到100的和</button>
    </body>
    </html>